var Customform_IntentionCollect01 = function() {
        var surplusTime = 0;
			var opts = {
			    customFormCategory : '',
			
			};
		
			var init = function(options) {
				$.extend(opts, options);
				var customFormCategory = opts.customFormCategory;
				var button1 = customFormCategory[0].button1;
				var button2 = customFormCategory[0].button2;
		        var openIntention = customFormCategory[0].status;
		        var onTime = customFormCategory[0].againalert;
		        
			//	var today = new Date();
		        var Title =customFormCategory[0].title;
				var connet=customFormCategory[0].content;
				var showmode=customFormCategory[0].showmode;
				var color = customFormCategory[0].color;
				var storage = window.localStorage;
				var beginTime = customFormCategory[0].firstalert;
			
				
		        var Intentiondate = storage.getItem("Intentiondate"); 
		        openTime = sessionStorage.getItem("openTimes");
		        
		        window.onload=showWindow; 
		        function showWindow(){
				  var surplusTimes = sessionStorage.getItem("surplusTimes");
		          if((openTime > surplusTimes || surplusTimes > openTime) && openTime>0){
		          var onloadTimes = openTime - surplusTimes;
		          setTimeout(function(){
			      storage.setItem("Intentiondate",new Date().getTime());
			      intention = new FUI.zpt_dialog({
	                    contents:"<div class=\"z3g-alertBox addSuccess\" >"
						+"<div class=\"alertBoxT\" style='background-color:"+color+"'>"+Title+"</div><div class=\"alertBoxC\">"+ connet
						+"</div><div class=\"alertBoxB\"><div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnCart\"  >"+button1+"</div>"
						+"<div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnClose\">"+button2+"</div></div></div> ",
	                    closeCallback: function() {
	                    }
	                });
	                
	                 $('#z3g-alertBtnClose').unbind(); 
	                 $('#z3g-alertBtnCart').unbind(); 
	                 $('#z3g-alertBtnClose').click(function() {
			          close_intention();
				      openTime = customFormCategory[0].againalert;
				      var openTimeMS = openTime*1000;
				      sessionStorage.removeItem("openTimes");
			          sessionStorage.setItem("openTimes",openTimeMS);
			          surplusTime = new Date().getTime();
			          sessionStorage.removeItem("historicalTime");
			          sessionStorage.setItem("historicalTime",new Date().getTime());
			          popCustom(openTimeMS);
					})
			
					$('#z3g-alertBtnCart').click(function() {
						close_intention();
				    	storage.setItem("isOpen","1");
					    sessionStorage.removeItem("openTimes");
					    sessionStorage.removeItem("historicalTime");
					    sessionStorage.removeItem("surplusTimes");
					    var url = '/intention_collect.html';
					    window.location.href=url;
					})
			        },onloadTimes);
		          }
				}
				window.onunload = allTimes;
				function allTimes(){
				var historicalTime = sessionStorage.getItem("historicalTime");
			    var surplusToday = new Date();
				var currentTime = surplusToday.getTime()
				if(historicalTime > 0){
			    var timeChas = currentTime - historicalTime;
			    sessionStorage.removeItem("surplusTimes");
			    sessionStorage.setItem("surplusTimes",timeChas);
			    }
			    
				}



		     if(openIntention == "1" && showmode == "1" && (Intentiondate == "" || Intentiondate == null)){
		     if(beginTime != "" && beginTime != null){
             var beginTimeMS = beginTime*1000;
	         setTimeout(function(){
			   storage.setItem("Intentiondate",new Date().getTime());
			      intention = new FUI.zpt_dialog({
	                    contents:"<div class=\"z3g-alertBox addSuccess\" >"
						+"<div class=\"alertBoxT\" style='background-color:"+color+"'>"+Title+"</div><div class=\"alertBoxC\">"+ connet
						+"</div><div class=\"alertBoxB\"><div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnCart\"  >"+button1+"</div>"
						+"<div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnClose\">"+button2+"</div></div></div> ",
	                    closeCallback: function() {
	                    }
	                });
	                
	                 $('#z3g-alertBtnClose').unbind(); 
	                 $('#z3g-alertBtnCart').unbind(); 
	                 $('#z3g-alertBtnClose').click(function() {
			          close_intention();
				      openTime = customFormCategory[0].againalert;
				      var openTimeMS = openTime*1000;
				      sessionStorage.removeItem("openTimes");
			          sessionStorage.setItem("openTimes",openTimeMS);
			          surplusTime = new Date().getTime();
			          sessionStorage.removeItem("historicalTime");
			          sessionStorage.setItem("historicalTime",new Date().getTime());
			         
			          popCustom(openTimeMS);
					})
			
					$('#z3g-alertBtnCart').click(function() {
						close_intention();
				    	storage.setItem("isOpen","1");
					    sessionStorage.removeItem("openTimes");
					    sessionStorage.removeItem("historicalTime");
					    sessionStorage.removeItem("surplusTimes");
					    var url = '/intention_collect.html';
					    window.location.href=url;
					})
			 },beginTimeMS);
			 }else{
			  storage.setItem("Intentiondate",new Date().getTime());
			      intention = new FUI.zpt_dialog({
	                    contents:"<div class=\"z3g-alertBox addSuccess\" >"
						+"<div class=\"alertBoxT\" style='background-color:"+color+"'>"+Title+"</div><div class=\"alertBoxC\">"+ connet
						+"</div><div class=\"alertBoxB\"><div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnCart\"  >"+button1+"</div>"
						+"<div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnClose\">"+button2+"</div></div></div> ",
	                    closeCallback: function() {}
	                });
	                $('#z3g-alertBtnClose').unbind(); 
	                $('#z3g-alertBtnCart').unbind(); 
	                $('#z3g-alertBtnClose').click(function() {
			          close_intention();
				      openTime = customFormCategory[0].againalert;
				      var openTimeMS = openTime*1000;
				      sessionStorage.removeItem("openTimes");
			          sessionStorage.setItem("openTimes",openTimeMS);
			          sessionStorage.removeItem("historicalTime");
			          sessionStorage.setItem("historicalTime",new Date().getTime());
			          surplusTime = new Date().getTime();
			          popCustom(openTimeMS);
					})
			
					$('#z3g-alertBtnCart').click(function() {
						close_intention();
				    	storage.setItem("isOpen","1");
					    sessionStorage.removeItem("openTimes");
					    sessionStorage.removeItem("historicalTime");
					    sessionStorage.removeItem("surplusTimes");
					    var url = '/intention_collect.html';
					    window.location.href=url;
					})
			 }
		    }
		 
		 
		 var popCustom = function(popTime){
			 if(popTime>0){
		 setTimeout(function(){
		   storage.setItem("Intentiondate",new Date().getTime());
		      intention = new FUI.zpt_dialog({
                    contents:"<div class=\"z3g-alertBox addSuccess\" >"
					+"<div class=\"alertBoxT\" style='background-color:"+color+"'>"+Title+"</div><div class=\"alertBoxC\">"+ connet
					+"</div><div class=\"alertBoxB\"><div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnCart\"  >"+button1+"</div>"
					+"<div class=\"z3g-alertBtn active\" id=\"z3g-alertBtnClose\">"+button2+"</div></div></div> ",
                    closeCallback: function() {
                    }
                });
                    $('#z3g-alertBtnClose').unbind(); 
	                $('#z3g-alertBtnCart').unbind(); 
                    $('#z3g-alertBtnClose').click(function() {
			        
			          close_intention();
			        
				      openTime = customFormCategory[0].againalert;
				      var openTimeMS = openTime*1000;
				      sessionStorage.removeItem("openTimes");
			          sessionStorage.setItem("openTimes",openTimeMS);
			          sessionStorage.removeItem("historicalTime");
			          sessionStorage.setItem("historicalTime",new Date().getTime());
			          surplusTime = new Date().getTime();
			          popCustom(openTimeMS);
					})
			
					$('#z3g-alertBtnCart').click(function() {
					    close_intention();
					    storage.setItem("isOpen","1");
					    sessionStorage.removeItem("openTimes");
					    sessionStorage.removeItem("historicalTime");
					    sessionStorage.removeItem("surplusTimes");
					    var url = '/intention_collect.html';
					    window.location.href=url;
						
					})
                
		 },popTime);
			 }
		 };
		  var isOpen = storage.getItem("isOpen");
		  if(openIntention == "1" && showmode == "2" && isOpen !="1"){
		  var footerDivHTML='';
	      footerDivHTML="<div class='intentPop'>"
	                   +"<div style='background-color:"+color+"'></div>"
			           +"<p id='footerId'>"+connet+"</p>"
		               +"</div>";
					    
		  $(".footerDiv").append(footerDivHTML);
		  var windowWidth = $(window).width();
		  
		  $('.intentPop').click(function() {
		    storage.setItem("isOpen","1");
		    var url = '/intention_collect.html';
		    window.location.href=url;
		  })
		  
		 
		  if($(".footerToolStyle3").length >0){
		     $(".intentPop").css("top","10px");
		  }
		  if($(".footerToolStyle2").length >0){
		     $(".intentPop").css("heigh","50px");
		     $(".footerToolStyle2 div").css("heigh","50px");
		  }
		
		  var footerWidth = parseFloat($("#footerId").width());
		  if(footerWidth > windowWidth ){
		  	$("#footerId").addClass("z3g-marquee");
		  	
		  }else{
            $("#footerId").removeClass("z3g-marquee");
		  
		  }
		}
		
        $('#z3g-alertBtnClose').click(function() {
          close_intention();
	      openTime = customFormCategory[0].againalert;
	      var openTimeMS = openTime*1000;
	      sessionStorage.removeItem("openTimes");
          sessionStorage.setItem("openTimes",openTimeMS);
          popCustom(openTimeMS);
		})

		$('#z3g-alertBtnCart').click(function() {
			close_intention();
		    storage.setItem("isOpen","1");
		    sessionStorage.removeItem("openTimes");
			sessionStorage.removeItem("historicalTime");
			sessionStorage.removeItem("surplusTimes");
		    var url = '/intention_collect.html';
		    window.location.href=url;
		})
		
		var close_intention=function(){
	        intention.warnClose();
        }
		
	};
	return {
		init : init
	}

}();